package com.tanhua.server.service;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.dubbo.config.annotation.Reference;
import com.tanhua.dubbo.server.api.RecommendUserApi;
import com.tanhua.dubbo.server.pojo.RecommendUser;
import com.tanhua.dubbo.server.vo.PageInfo;
import com.tanhua.common.pojo.UserInfo;
import com.tanhua.server.vo.TodayBest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 调用dubbo查询今日佳人的id信息
 */
@Service
@Slf4j
public class RecommendUserService {

    @Reference(version = "1.0.0")
    private RecommendUserApi recommendUserApi;

    public TodayBest queryTodayBest(Long id) {
        //调用dubbo服务查询当前用户的今日佳人id
        RecommendUser recommendUser = recommendUserApi.queryWithMaxScore(id);
        if (recommendUser == null){
            log.info("通过dubbo查询到的今日佳人为null");
            return null;
        }

        TodayBest todayBest = new TodayBest();
        todayBest.setId(recommendUser.getUserId());
        todayBest.setFateValue(recommendUser.getScore().longValue());
        return todayBest;
    }

    /**
     * 调用dubbo服务查询推荐用户列表
     * @param id
     * @param page
     * @param pagesize
     * @return
     */
    public PageInfo<RecommendUser> queryRecommendUserList(Long id, Integer page, Integer pagesize) {
        PageInfo<RecommendUser> recommendUserPageInfo = recommendUserApi.queryPageInfo(id, page, pagesize);
        return recommendUserPageInfo;
    }

    /**
     * 查询推荐好友的缘分值
     *
     * @param userId
     * @param toUserId
     * @return
     */
    public Double queryScore(Long userId, Long toUserId){
        Double score = this.recommendUserApi.queryScore(userId, toUserId);
        if(ObjectUtil.isNotEmpty(score)){
            return score;
        }
        //默认值
        return 98d;
    }

    public List<RecommendUser> queryCardList(Long id, int count) {
        return recommendUserApi.queryCardList(id,count);
    }
}
